package Classes.Objects.Personagens.Inimigos 
{
	import Box2D.Common.Math.b2Vec2;
	import Classes.core.World;
	import Classes.Objects.Personagens.Inimigo;
	/**
	 * ...
	 * @author StrongLight
	 */
	public class Voador extends Inimigo
	{	
		private var spawnPointX:Number;
		private var spawnPointY:Number;
		
		private var position:b2Vec2;
		
		[Property(value = "100")]
		private var flyingRangeX:Number = 100;
		
		[Property(value = "20")]
		private var flyingRangeY:Number = 20;
		
		[Property(value = "1")]
		private var flyingVelocityX:Number = 1;
		
		[Property(value = "1")]
		private var flyingVelocityY:Number = 0.5;
		
		public function Voador(world: World, isStatic:Boolean, x: Number, y: Number, width: Number, height: Number, artName: String,rotation:Number) 
		{
			super(world, isStatic, x, y, width, height, artName, rotation);
			
			flyingVelocityX = flyingVelocityX / 20;
			flyingVelocityY = flyingVelocityY / 20;

			position = new b2Vec2(x / 20, y / 20);
			
			spawnPointX = x / 20;
			spawnPointY = y / 20;
			
		}
		
		public override function update():void
		{
			flyingRangeX = this.body.GetPosition().x - spawnPointX;			
			//trace (flyingRangeX);
			
			flyingRangeY = this.body.GetPosition().y - spawnPointY;
			//trace ("RANGE" + flyingRangeY);
			
			//flyingVelocityY = 0.5 - flyingRangeY;
			//trace (flyingVelocityY)
			
			if (Math.abs(flyingRangeX) > 5)
			{
				flyingVelocityX *= -1;
				this.art.scaleX *= -1;
			}
			
			if (flyingRangeY > 0)
			{
				flyingVelocityY += 0.001;
			}
			
			else
			{
				flyingVelocityY -= 0.001;
			}
			
			
			position.x -= flyingVelocityX;
			position.y -= flyingVelocityY;
			
			this.body.SetPosition(position)
			//trace (position.x,position.y)
			super.update();
			
		}
		
	}

}